<!--采购管理-待结算明细-->
<template>
  <div class="settlement-detail-box">
    <el-container class="template-box">
      <!--tab切换-->
      <tabs
        class="tabs"
        :active-index="tabIndex"
        :tabs-arr="accountTabsArr"
        @returnIndex="tabsHandle"
      />
      <!--搜索-->
      <el-header height="auto">
        <SearchForm
          label-width="110px"
          :data="accountSearchData"
          :compact-data="accountSearchData.slice(0,2)"
          show-collapse
          @searchForm="searchForm"
          @resetForm="resetForm"
          :submit-loading="submitLoading"
        />
      </el-header>
      <div class="money">
        <i
          class="el-icon-warning-outline"
          @click="change('click')"
          @mouseleave="change('move')" />
        <div
          class="tip"
          v-if="changeshow">该金额合计仅供参考，实际月结算金额和该统计金额，可能存在差异。</div>金额合计（元）：
        <span class="moneynum">{{ allAmount }}</span>
      </div>
      <!-- 列表 -->
      <el-editable
        v-loading="submitLoading"
        :data="dataList"
        height="400"
        :columns="columsData">
        <template
          slot="default-prodRegistNo"
          slot-scope="scope">
          <el-button
            type="text"
            @click="prodRegistNo(scope,0)">{{ scope.row.prodRegistNo }}</el-button>
        </template>
      </el-editable>
      <!-- 分页模块 -->
      <el-pagination
        class="pagination"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="curPage"
        :page-sizes="PAGE_NUMBER"
        :page-size="pageSize"
        :layout="PAGINATION_LAYOUT"
        :total="totalElements"
      />

      <!-- 注册证查看大图 -->
      <el-dialog
        title="注册证图片"
        :visible.sync="imgVisible"
        style="margin-top:10%;"
        width="400px">
        <div>
          <el-image
            :src="pictureUrl"
            style="width: 100%;" />
        </div>
      </el-dialog>
    </el-container>
  </div>
</template>

<script>
import {
  hospitalSettleDailyList,
  hospitalSettleStatisDailyCount
} from '@const/beforeSettleApi'
import tabs from '@components/tabs/index.vue'
import SearchForm from '@components/businesscomponents/search'
import ElEditable from '@components/el-editable'
import { accountTabsArr, accountSearchData, columsData } from './const'
import { PAGE_NUMBER, PAGINATION_LAYOUT } from '@const/common'
import { hasIn, cloneDeep } from 'lodash'
import { getFormatterPrice } from '@const/filter'
export default {
  components: { tabs, SearchForm, ElEditable },
  data () {
    return {
      tabIndex: 4, // tab默认选项
      accountTabsArr: cloneDeep(accountTabsArr), // tab切换字段
      accountSearchData, // 搜索框字段
      // 搜索返回内容
      searchData: {},
      dataList: [], // 列表数据
      columsData, // 列表表头
      submitLoading: false,
      changeshow: false, // 是否显示提示
      accountStatus: 0, // 进行不同状态的数据查询
      allAmount: 0, // 默认钱数
      imgVisible: false, // 注册证大图
      pictureUrl: '',
      curPage: 1, // 当前页
      PAGE_NUMBER, // 页码数组
      PAGINATION_LAYOUT, // 页码功能布局
      pageSize: PAGE_NUMBER[0], // 一页的数量
      totalElements: 0 // 总共的条数
    }
  },
  mounted () {
    this.getList()
    this.getCount()
  },
  methods: {
    // 获取列表
    async getList () {
      this.submitLoading = true
      const res = await this.$axios({
        method: 'post',
        url: hospitalSettleDailyList,
        data: {
          ...this.searchData,
          orderStatus: this.accountStatus,
          page: this.curPage,
          pageSize: this.pageSize,
          type: 1
        }
      })
      this.dataList = hasIn(res, ['data', 'payload'])
        ? res.data.payload.settleOrderItemList.content || []
        : []
      this.allAmount = res.data.payload.allAmount === 0 ? 0 : getFormatterPrice(res.data.payload.allAmount)
      // this.allAmount = getFormatterPrice(res.data.payload.allAmount)
      this.totalElements = res.data.payload.settleOrderItemList.totalElements
      this.submitLoading = false
    },
    // 根据状态获取对应数量
    async getCount () {
      const res = await this.$axios({
        method: 'post',
        url: hospitalSettleStatisDailyCount
      })
      let arr = hasIn(res, 'data.payload') ? res.data.payload : []
      const cloneIndexTabs = cloneDeep(accountTabsArr)
      cloneIndexTabs.forEach(item => {
        arr.forEach(ite => {
          if (ite.statusCode === item.val) {
            item.badge = { value: ite.count }
          }
        })
        if (item.val === 0) {
          item.badge.value = 0
          arr.forEach(ite => {
            item.badge.value += Number(ite.count)
          })
        }
      })
      this.accountTabsArr = cloneIndexTabs
    },
    // tab处理事件
    tabsHandle (index) {
      this.accountStatus =
        this.accountTabsArr[index].val === 'null'
          ? null
          : this.accountTabsArr[index].val
      this.curPage = 1
      this.getList()
    },
    // 搜索框搜索事件
    searchForm (condition) {
      this.searchData = condition
      this.getList()
    },
    // 搜索框重置事件
    resetForm (condition) {
      this.searchData = condition
      this.curPage = 1
      this.getList()
    },
    // 页码更改
    handleSizeChange (size) {
      this.pageSize = size
      this.getList()
    },
    // 切换不一样的页面,重置一切数据
    handleCurrentChange (curPage) {
      this.curPage = curPage
      this.getList()
    },
    // 点击注册证备案号预览图片
    prodRegistNo (val) {
      this.pictureUrl = val.row.prodRegistNo
      this.imgVisible = true
    },

    // 提示事件
    change (type) {
      if (type === 'click') {
        this.changeshow = true
      } else {
        this.changeshow = false
      }
    }
  }
}
</script>

<style lang='less' scoped>
.settlement-detail-box {
  .template-box {
    height: 100%;
    overflow: auto;
    /deep/.tabs .tabs-item {
      &.active {
        .item-font {
          font-size: 14px;
          transform: scale(1.3);
          transition: all 0.3s ease;
        }
      }
    }
    .pagination {
      padding-top: 10px;
      display: flex;
      justify-content: flex-end;
      padding-right: 0;
    }
    .money {
      position: relative;
      padding-left: 12px;
      margin: 10px 0;
      font-size: 16px;
      .tip {
        width: 340px;
        padding: 5px 9px;
        background: #000;
        color: #fff;
        position: absolute;
        top: 0;
        left: 37px;
        z-index: 999;
      }
      .el-icon-warning-outline {
        cursor: pointer;
      }
      .moneynum {
        color: red;
      }
    }
  }
}
</style>
